
#include "pch.h"
#include "RADiskCore.h"




typedef  DWORD(WINAPI* pFuncInitAtaSmart)();
typedef  DWORD(WINAPI* pFuncGetAllDiskCount)();

typedef  DWORD(WINAPI* pFuncGetFirmwareRev)		(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetSerialNumber)	(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetInterface)		(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetMajorVersion)	(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetMinorVersion)	(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetCurTransMode)	(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetCurMaxMode)		(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetSupportMode)		(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetModelSerial)		(int, LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetDriverMap)		(int, LPCWSTR*);


typedef  DWORD(WINAPI* pFuncGetHostWrites)		(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetHostReads)		(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetPowerOnCount)	(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetPowerOnHours)	(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetTemperature)		(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetLife)			(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetTotalDiskSize)	(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetAttributeCount)	(int, LPDWORD);
typedef  DWORD(WINAPI* pFuncGetAttributeData)	(int, DWORD, LPCWSTR*, LPCWSTR*);


typedef  DWORD(WINAPI* pFuncIsSSD)					(int,PBOOL);
typedef  DWORD(WINAPI* pFuncStartDiskTRIM)			(int);
typedef  DWORD(WINAPI* pFuncStartDiskOverWriting)	(int);
typedef  DWORD(WINAPI* pFuncGetSystemTime)		(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetSystemName)		(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetSystemCurLanguage)	(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetOsCreater)		(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetBiosVersion)		(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetOsType)			(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetCPUMsg)			(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetMemoryMsg)		(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetMainBoardMsg)	(LPCWSTR*);
typedef  DWORD(WINAPI* pFuncGetWorkGroup)		(LPCWSTR*);



static  pFuncInitAtaSmart			s_pFuncInitAtaSmart			   = NULL;
static  pFuncGetAllDiskCount		s_pFuncGetAllDiskCount		   = NULL;
static  pFuncGetFirmwareRev			s_pFuncGetFirmwareRev		   = NULL;
static  pFuncGetSerialNumber		s_pFuncGetSerialNumber		   = NULL;
static  pFuncGetInterface			s_pFuncGetInterface			   = NULL;
static  pFuncGetMajorVersion		s_pFuncGetMajorVersion		   = NULL;
static  pFuncGetMinorVersion		s_pFuncGetMinorVersion		   = NULL;
static  pFuncGetCurTransMode		s_pFuncGetCurTransMode		   = NULL;
static  pFuncGetCurMaxMode			s_pFuncGetCurMaxMode		   = NULL;
static  pFuncGetSupportMode			s_pFuncGetSupportMode		   = NULL;
static  pFuncGetModelSerial			s_pFuncGetModelSerial		   = NULL;
static  pFuncGetDriverMap			s_pFuncGetDriverMap			   = NULL;
static  pFuncGetHostWrites			s_pFuncGetHostWrites		   = NULL;
static  pFuncGetHostReads			s_pFuncGetHostReads			   = NULL;
static  pFuncGetPowerOnCount		s_pFuncGetPowerOnCount		   = NULL;
static  pFuncGetPowerOnHours		s_pFuncGetPowerOnHours		   = NULL;
static  pFuncGetTemperature			s_pFuncGetTemperature		   = NULL;
static  pFuncGetLife				s_pFuncGetLife				   = NULL;
static  pFuncGetTotalDiskSize		s_pFuncGetTotalDiskSize		   = NULL;
static  pFuncGetAttributeCount		s_pFuncGetAttributeCount	   = NULL;
static  pFuncGetAttributeData		s_pFuncGetAttributeData		   = NULL;
static  pFuncStartDiskTRIM			s_pFuncStartDiskTRIM		   = NULL;
static  pFuncStartDiskOverWriting	s_pFuncStartDiskOverWriting	   = NULL;
static  pFuncGetSystemTime			s_pFuncGetSystemTime		   = NULL;
static  pFuncGetSystemName			s_pFuncGetSystemName		   = NULL;
static  pFuncGetSystemCurLanguage	s_pFuncGetSystemCurLanguage	   = NULL;
static  pFuncGetOsCreater			s_pFuncGetOsCreater			   = NULL;
static  pFuncGetBiosVersion			s_pFuncGetBiosVersion		   = NULL;
static  pFuncGetOsType				s_pFuncGetOsType			   = NULL;
static  pFuncGetCPUMsg				s_pFuncGetCPUMsg			   = NULL;
static  pFuncGetMemoryMsg			s_pFuncGetMemoryMsg			   = NULL;
static  pFuncGetMainBoardMsg		s_pFuncGetMainBoardMsg		   = NULL;
static  pFuncGetWorkGroup			s_pFuncGetWorkGroup			   = NULL;
static	pFuncIsSSD					s_pFuncIsSSD				   = NULL;


BOOL		CRADiskCore::m_bInit = FALSE;
HMODULE		CRADiskCore::m_hMod = NULL;


BOOL CRADiskCore::Initialize()
{
	if (m_bInit)
		return TRUE;

	m_bInit = TRUE;


	BOOL bRet = FALSE;
	m_hMod = LoadLibrary(RADISKCORENAME);

	if (m_hMod != NULL)
	{
		INI_FUNC_ADDR(s_pFuncInitAtaSmart,			pFuncInitAtaSmart,			m_hMod,			"InitAtaSmart");
		INI_FUNC_ADDR(s_pFuncGetAllDiskCount,		pFuncGetAllDiskCount,		m_hMod,			"GetAllDiskCount");

		INI_FUNC_ADDR(s_pFuncGetFirmwareRev,		pFuncGetFirmwareRev,		m_hMod,			"GetFirmwareRev");
		INI_FUNC_ADDR(s_pFuncGetSerialNumber,		pFuncGetSerialNumber,		m_hMod,			"GetSerialNumber");
		INI_FUNC_ADDR(s_pFuncGetInterface,			pFuncGetInterface,			m_hMod,			"GetInterface");
		INI_FUNC_ADDR(s_pFuncGetMajorVersion,		pFuncGetMajorVersion,		m_hMod,			"GetMajorVersion");
		INI_FUNC_ADDR(s_pFuncGetMinorVersion,		pFuncGetMinorVersion,		m_hMod,			"GetMinorVersion");
		INI_FUNC_ADDR(s_pFuncGetCurTransMode,		pFuncGetCurTransMode,		m_hMod,			"GetCurTransMode");
		INI_FUNC_ADDR(s_pFuncGetCurMaxMode,			pFuncGetCurMaxMode,			m_hMod,			"GetCurMaxMode");
		INI_FUNC_ADDR(s_pFuncGetSupportMode,		pFuncGetSupportMode,		m_hMod,			"GetSupportMode");
		INI_FUNC_ADDR(s_pFuncGetModelSerial,		pFuncGetModelSerial,		m_hMod,			"GetModelSerial");
		INI_FUNC_ADDR(s_pFuncGetHostWrites,			pFuncGetHostWrites,			m_hMod,			"GetHostWrites");
		INI_FUNC_ADDR(s_pFuncGetDriverMap,			pFuncGetDriverMap,			m_hMod,			"GetDriverMap");

		INI_FUNC_ADDR(s_pFuncGetHostReads,			pFuncGetHostReads,			m_hMod,			"GetHostReads");
		INI_FUNC_ADDR(s_pFuncGetPowerOnCount,		pFuncGetPowerOnCount,		m_hMod,			"GetPowerOnCount");
		INI_FUNC_ADDR(s_pFuncGetPowerOnHours,		pFuncGetPowerOnHours,		m_hMod,			"GetPowerOnHours");
		INI_FUNC_ADDR(s_pFuncGetTemperature,		pFuncGetTemperature,		m_hMod,			"GetTemperature");
		INI_FUNC_ADDR(s_pFuncGetLife,				pFuncGetLife,				m_hMod,			"GetLife");
		INI_FUNC_ADDR(s_pFuncGetTotalDiskSize,		pFuncGetTotalDiskSize,		m_hMod,			"GetTotalDiskSize");
		INI_FUNC_ADDR(s_pFuncGetAttributeCount,		pFuncGetAttributeCount,		m_hMod,			"GetAttributeCount");
		INI_FUNC_ADDR(s_pFuncGetAttributeData,		pFuncGetAttributeData,		m_hMod,			"GetAttributeData");
		INI_FUNC_ADDR(s_pFuncStartDiskTRIM,			pFuncStartDiskTRIM,			m_hMod,			"StartDiskTRIM	");
		INI_FUNC_ADDR(s_pFuncStartDiskOverWriting,	pFuncStartDiskOverWriting,	m_hMod,			"StartDiskOverWriting");
		INI_FUNC_ADDR(s_pFuncGetSystemTime,			pFuncGetSystemTime,			m_hMod,			"GetSystemTime");
		INI_FUNC_ADDR(s_pFuncGetSystemName,			pFuncGetSystemName,			m_hMod,			"GetSystemName");
		INI_FUNC_ADDR(s_pFuncGetSystemCurLanguage,	pFuncGetSystemCurLanguage,	m_hMod,			"GetSystemCurLanguage");
		INI_FUNC_ADDR(s_pFuncGetOsCreater,			pFuncGetOsCreater,			m_hMod,			"GetOsCreater");
		INI_FUNC_ADDR(s_pFuncGetBiosVersion,		pFuncGetBiosVersion,		m_hMod,			"GetBiosVersion");
		INI_FUNC_ADDR(s_pFuncGetOsType,				pFuncGetOsType,				m_hMod,			"GetOsType");
		INI_FUNC_ADDR(s_pFuncGetCPUMsg,				pFuncGetCPUMsg,				m_hMod,			"GetCPUMsg");
		INI_FUNC_ADDR(s_pFuncGetMemoryMsg,			pFuncGetMemoryMsg,			m_hMod,			"GetMemoryMsg");
		INI_FUNC_ADDR(s_pFuncGetMainBoardMsg,		pFuncGetMainBoardMsg,		m_hMod,			"GetMainBoardMsg");
		INI_FUNC_ADDR(s_pFuncGetWorkGroup,			pFuncGetWorkGroup,			m_hMod,			"pFuncGetWorkGroup");
	}

#ifdef  _DEBUG
	if (
		(s_pFuncInitAtaSmart != NULL)
		&& (s_pFuncGetAllDiskCount != NULL)
		&& (s_pFuncGetFirmwareRev != NULL)
		&& (s_pFuncGetSerialNumber != NULL)
		&& (s_pFuncGetInterface != NULL)
		&& (s_pFuncGetMajorVersion != NULL)
		&& (s_pFuncGetMinorVersion != NULL)
		&& (s_pFuncGetCurTransMode != NULL)
		&& (s_pFuncGetCurMaxMode != NULL)
		&& (s_pFuncGetSupportMode != NULL)
		&& (s_pFuncGetModelSerial != NULL)
		&& (s_pFuncGetHostWrites != NULL)
		&& (s_pFuncGetHostReads != NULL)
		&& (s_pFuncGetPowerOnCount != NULL)
		&& (s_pFuncGetPowerOnHours != NULL)
		&& (s_pFuncGetTemperature != NULL)
		&& (s_pFuncGetLife != NULL)
		&& (s_pFuncGetTotalDiskSize != NULL)
		&& (s_pFuncGetAttributeCount != NULL)
		&& (s_pFuncGetAttributeData != NULL)
		&& (s_pFuncStartDiskTRIM != NULL)
		&& (s_pFuncStartDiskOverWriting != NULL)
		&& (s_pFuncGetSystemTime != NULL)
		&& (s_pFuncGetSystemName != NULL)
		&& (s_pFuncGetSystemCurLanguage != NULL)
		&& (s_pFuncGetOsCreater != NULL)
		&& (s_pFuncGetBiosVersion != NULL)
		&& (s_pFuncGetOsType != NULL)
		&& (s_pFuncGetCPUMsg != NULL)
		&& (s_pFuncGetMemoryMsg != NULL)
		&& (s_pFuncGetMainBoardMsg != NULL)
		&& (s_pFuncGetWorkGroup != NULL)
		)
#endif //  	DEBUG
	{
		bRet = TRUE;
	}

	return bRet;
}


BOOL CRADiskCore::Uninitialize()
{
	if (m_hMod != NULL)
	{
		m_hMod = NULL;
		s_pFuncInitAtaSmart = NULL;
		s_pFuncGetAllDiskCount = NULL;
	}
	return TRUE;
}


DWORD  CRADiskCore::InitAtaSmart()
{
	Initialize();

	if (s_pFuncInitAtaSmart != NULL)
	{
		return s_pFuncInitAtaSmart();
	}

	return S_FALSE;
}

DWORD  CRADiskCore::GetAllDiskCount()
{
	Initialize();

	if (s_pFuncGetAllDiskCount != NULL)
	{
		return s_pFuncGetAllDiskCount();
	}

	return S_FALSE;
}

DWORD CRADiskCore::GetFirmwareRev(int iIndex, LPCWSTR* ppFirmwareRev)
{

	Initialize();

	if (s_pFuncGetFirmwareRev != NULL)
	{
		return s_pFuncGetFirmwareRev(iIndex, ppFirmwareRev);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetSerialNumber(int iIndex, LPCWSTR* ppSerialNumber)
{

	Initialize();

	if (s_pFuncGetSerialNumber != NULL)
	{
		return s_pFuncGetSerialNumber(iIndex, ppSerialNumber);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetHostWrites(int iIndex, LPDWORD pdwWrites)
{
	Initialize();

	if (s_pFuncGetHostWrites != NULL)
	{
		return s_pFuncGetHostWrites(iIndex, pdwWrites);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetHostReads(int iIndex, LPDWORD pdwReads)
{
	Initialize();

	if (s_pFuncGetHostReads != NULL)
	{
		return s_pFuncGetHostReads(iIndex, pdwReads);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetPowerOnCount(int iIndex, LPDWORD pdwPowerCount)
{
	Initialize();

	if (s_pFuncGetPowerOnCount != NULL)
	{
		return s_pFuncGetPowerOnCount(iIndex, pdwPowerCount);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetPowerOnHours(int iIndex, LPDWORD pdwPowerHours)
{
	Initialize();

	if (s_pFuncGetPowerOnHours != NULL)
	{
		return s_pFuncGetPowerOnHours(iIndex, pdwPowerHours);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetInterface(int iIndex, LPCWSTR* ppInterface)
{
	Initialize();

	if (s_pFuncGetInterface != NULL)
	{
		return s_pFuncGetInterface(iIndex, ppInterface);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetMajorVersion(int iIndex, LPCWSTR* ppMajorVersion)
{
	Initialize();

	if (s_pFuncGetMajorVersion != NULL)
	{
		return s_pFuncGetMajorVersion(iIndex, ppMajorVersion);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetMinorVersion(int iIndex, LPCWSTR* ppMinorVersion)
{
	Initialize();

	if (s_pFuncGetMinorVersion != NULL)
	{
		return s_pFuncGetMinorVersion(iIndex, ppMinorVersion);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetCurTransMode(int iIndex, LPCWSTR* ppCurTransMode)
{
	Initialize();

	if (s_pFuncGetCurTransMode != NULL)
	{
		return s_pFuncGetCurTransMode(iIndex, ppCurTransMode);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetCurMaxMode(int iIndex, LPCWSTR* ppCurMaxMode)
{
	Initialize();

	if (s_pFuncGetCurMaxMode != NULL)
	{
		return s_pFuncGetCurMaxMode(iIndex, ppCurMaxMode);
	}

	return S_FALSE;

}
DWORD CRADiskCore::IsSSD(int iIndex, PBOOL pbIsssd)
{

	Initialize();

	if (s_pFuncIsSSD != NULL)
	{
		return s_pFuncIsSSD(iIndex, pbIsssd);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetTemperature(int iIndex, LPDWORD pdwTemperature)
{

	Initialize();

	if (s_pFuncGetTemperature != NULL)
	{
		return s_pFuncGetTemperature(iIndex, pdwTemperature);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetLife(int iIndex, LPDWORD pdwLife)
{
	Initialize();

	if (s_pFuncGetLife != NULL)
	{
		return s_pFuncGetLife(iIndex, pdwLife);
	}

	return S_FALSE;

}
DWORD CRADiskCore::GetSupportMode(int iIndex, LPCWSTR* ppSupportMode)
{
	Initialize();

	if (s_pFuncGetSupportMode != NULL)
	{
		return s_pFuncGetSupportMode(iIndex, ppSupportMode);
	}

	return S_FALSE;

}
DWORD CRADiskCore::GetModelSerial(int iIndex, LPCWSTR* ppModelSerial)
{

	Initialize();

	if (s_pFuncGetModelSerial != NULL)
	{
		return s_pFuncGetModelSerial(iIndex, ppModelSerial);
	}

	return S_FALSE;
}

DWORD CRADiskCore::GetDriverMap(int iIndex, LPCWSTR* ppDriverMap)
{
	Initialize();

	if (s_pFuncGetDriverMap != NULL)
	{
		return s_pFuncGetDriverMap(iIndex, ppDriverMap);
	}

	return S_FALSE;
}

DWORD CRADiskCore::GetTotalDiskSize(int iIndex, LPDWORD pdwTotalSize)
{
	Initialize();

	if (s_pFuncGetTotalDiskSize != NULL)
	{
		return s_pFuncGetTotalDiskSize(iIndex, pdwTotalSize);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetAttributeCount(int iIndex, LPDWORD pdwAttributeCount)
{

	Initialize();

	if (s_pFuncGetAttributeCount != NULL)
	{
		return s_pFuncGetAttributeCount(iIndex, pdwAttributeCount);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetAttributeData(int iIndex, DWORD dwAttributeIndex, LPCWSTR* ppAttributeName, LPCWSTR* ppAttributeVal)
{
	Initialize();

	if (s_pFuncGetAttributeData != NULL)
	{
		return s_pFuncGetAttributeData(iIndex, dwAttributeIndex, ppAttributeName, ppAttributeVal);
	}

	return S_FALSE;
}

DWORD CRADiskCore::StartDiskTRIM(int iIndex)
{
	Initialize();

	if (s_pFuncStartDiskTRIM != NULL)
	{
		return s_pFuncStartDiskTRIM(iIndex);
	}

	return S_FALSE;
}
DWORD CRADiskCore::StartDiskOverWriting(int iIndex)
{
	Initialize();

	if (s_pFuncStartDiskOverWriting != NULL)
	{
		return s_pFuncStartDiskOverWriting(iIndex);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetSystemTime(LPCWSTR* ppSystemTime)
{
	Initialize();

	if (s_pFuncGetSystemTime != NULL)
	{
		return s_pFuncGetSystemTime(ppSystemTime);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetSystemName(LPCWSTR* ppSystemName)
{
	Initialize();

	if (s_pFuncGetSystemName != NULL)
	{
		return s_pFuncGetSystemName(ppSystemName);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetSystemCurLanguage(LPCWSTR* ppSysLanguage)
{
	Initialize();

	if (s_pFuncGetSystemCurLanguage != NULL)
	{
		return s_pFuncGetSystemCurLanguage(ppSysLanguage);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetOsCreater(LPCWSTR* ppOsCreater)
{

	Initialize();

	if (s_pFuncGetOsCreater != NULL)
	{
		return s_pFuncGetOsCreater(ppOsCreater);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetBiosVersion(LPCWSTR* ppBiosVersion)
{
	Initialize();

	if (s_pFuncGetBiosVersion != NULL)
	{
		return s_pFuncGetBiosVersion(ppBiosVersion);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetOsType(LPCWSTR* ppOsType)
{
	Initialize();

	if (s_pFuncGetOsType != NULL)
	{
		return s_pFuncGetOsType(ppOsType);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetCPUMsg(LPCWSTR* ppCPUMsg)
{
	Initialize();

	if (s_pFuncGetCPUMsg != NULL)
	{
		return s_pFuncGetCPUMsg(ppCPUMsg);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetMemoryMsg(LPCWSTR* ppMemMsg)
{
	Initialize();

	if (s_pFuncGetMemoryMsg != NULL)
	{
		return s_pFuncGetMemoryMsg(ppMemMsg);
	}

	return S_FALSE;
}
DWORD CRADiskCore::GetMainBoardMsg(LPCWSTR* ppMainBoardMsg)
{
	Initialize();

	if (s_pFuncGetMainBoardMsg != NULL)
	{
		return s_pFuncGetMainBoardMsg(ppMainBoardMsg);
	}

	return S_FALSE;

}
DWORD CRADiskCore::GetWorkGroup(LPCWSTR* ppWorkGroup)
{
	Initialize();

	if (s_pFuncGetWorkGroup != NULL)
	{
		return s_pFuncGetWorkGroup(ppWorkGroup);
	}

	return S_FALSE;
}


